<?php
/**
 * 检查系统用户管理菜单是否存在
 */

// 使用SQLite数据库
$dbPath = __DIR__ . '/database/sqlite.db';

try {
    $dsn = "sqlite:{$dbPath}";
    $pdo = new PDO($dsn);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 检查系统用户管理菜单 ===\n\n";
    
    // 查询所有菜单
    $stmt = $pdo->query("SELECT id, pid, title, node, icon, url, status FROM system_menu ORDER BY pid, sort DESC, id");
    $menus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "数据库中共有 " . count($menus) . " 条菜单记录\n\n";
    
    // 查找用户管理相关菜单
    echo "=== 查找用户管理相关菜单 ===\n";
    $found = false;
    foreach ($menus as $menu) {
        if (stripos($menu['title'], '用户') !== false || stripos($menu['node'], 'user') !== false) {
            $status = $menu['status'] == 1 ? '启用' : '禁用';
            echo "ID:{$menu['id']} | PID:{$menu['pid']} | 标题:{$menu['title']} | 节点:{$menu['node']} | 状态:{$status}\n";
            $found = true;
        }
    }
    
    if (!$found) {
        echo "❌ 未找到用户管理相关菜单！\n\n";
        echo "=== 所有一级菜单 ===\n";
        foreach ($menus as $menu) {
            if ($menu['pid'] == 0) {
                $status = $menu['status'] == 1 ? '启用' : '禁用';
                echo "ID:{$menu['id']} | 标题:{$menu['title']} | 节点:{$menu['node']} | 状态:{$status}\n";
            }
        }
    } else {
        echo "\n✓ 找到用户管理菜单\n";
    }
    
    // 查找权限管理相关菜单
    echo "\n=== 查找权限管理相关菜单 ===\n";
    foreach ($menus as $menu) {
        if (stripos($menu['title'], '权限') !== false || stripos($menu['node'], 'auth') !== false) {
            $status = $menu['status'] == 1 ? '启用' : '禁用';
            echo "ID:{$menu['id']} | PID:{$menu['pid']} | 标题:{$menu['title']} | 节点:{$menu['node']} | 状态:{$status}\n";
        }
    }
    
} catch (PDOException $e) {
    echo "数据库错误: " . $e->getMessage() . "\n";
}

